package com.ucode.model.cgms.form;

import cn.hutool.core.util.ObjUtil;
import com.ucode.model.cgms.enums.CgmsRewardTypeEnum;
import com.ucode.tool.validator.InEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

/**
 * 礼物配置Form
 * @Author: liliang
 * @Date: 2025/5/11 13:54
 * @Version: 1.0
 */
@Schema(description = "陪玩俱乐部社区系统 - 礼物打赏订单Form")
@Data
@EqualsAndHashCode
@ToString(callSuper = true)
public class CgmsGiftRewardOrderForm {

    /**
     * 打赏类型：1 礼物打赏 2 自定义打赏
     */
    @Schema(description = "打赏类型：1 礼物打赏 2 自定义打赏", requiredMode = Schema.RequiredMode.AUTO)
    @NotNull(message = "打赏类型不能为空")
    @InEnum(value = CgmsRewardTypeEnum.class, message = "打赏类型不正确")
    private Integer rewardType;

    /**
     * 礼物ID
     */
    @Schema(description = "礼物ID", requiredMode = Schema.RequiredMode.AUTO)
    private Long giftId;

    /**
     * 陪玩用户ID
     */
    @Schema(description = "陪玩用户ID", requiredMode = Schema.RequiredMode.AUTO)
    private Long companionUserId;

    /**
     * 打赏留言
     */
    @Schema(description = "打赏留言", requiredMode = Schema.RequiredMode.AUTO)
    private String remark;
    /**
     * 打赏金额
     */
    @Schema(description = "打赏金额", requiredMode = Schema.RequiredMode.AUTO)
//    @NotNull(message = "打赏金额不能为空")
//    @DecimalMin(value = "0",message = "打赏金额最小值为 0")
//    @Digits(integer = 10,fraction = 2,message = "打赏金额格式不正确")
    private BigDecimal amount;

    /**
     * 礼物数量
     */
    @Schema(description = "礼物数量", requiredMode = Schema.RequiredMode.AUTO)
//    @NotNull(message = "礼物数量不能为空")
//    @Min(value = 1,message = "礼物数量最小值为 1")
//    @Max(value = 9999,message = "礼物数量最大值为 9999")
    private Integer quantity;

    /**
     * 是否匿名打赏
     */
    @Schema(description = "是否匿名打赏", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "是否匿名打赏不能为空")
    private Boolean anonymityState;

    @Schema(description = "支付应用编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    @NotNull(message = "支付应用编码不能为空")
    private Long payAppId;
    /**
     * 如果是礼物打赏 判断礼物编号和我礼物数量不能为空
     */
    @AssertTrue(message = "礼物ID不能为空")
    public boolean isGiftId() {
        if(this.rewardType == 1){
            if(ObjUtil.isNull(this.getGiftId())){
                return false;
            }
        }
        return true;
    }

    /**
     * 如果是礼物打赏 礼物数量不能为空
     */
    @AssertTrue(message = "礼物数量不能为空")
    public boolean isGiftQuantity() {
        if(this.rewardType == 1){
            if(ObjUtil.isNull(this.getQuantity())){
                return false;
            }
        }
        return true;
    }

    /**
     * 如果是自定义打赏
     * 判断打赏金额不能为空
     * 判断打赏金额格式不正确
     */
    @AssertTrue(message = "礼物数量不能为空")
    public boolean isAmount() {
        if(this.rewardType == 2){
            if(ObjUtil.isNull(this.getAmount())){
                return false;
            }
        }
        return true;
    }



}
